﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;


namespace ZenHR.AttData.Collection.Util
{
   public static class CommonHelper
    {

        /// <summary>
        /// 保存配置
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public static void SaveConfig(string key, string value)
        {
            try
            {
                Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

                //make changes
                config.AppSettings.Settings[key].Value = value;

                //save to apply changes
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("appSettings");
            }
            catch (Exception ex)
            {

                throw (ex);
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string GetConfig(string key)
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            //make changes
            return config.AppSettings.Settings[key].Value;
        }

    }
}
